SwordGrid.implement({
	
	initEvents:function(){
    	this.eDelegator=new SwordEventDelegator({'container':this.options.pNode});
    	
    	//收缩展开表格
    	this.eDelegator.add('click',this.collapseClickDele.bind(this),'div[eventDele=collapse]'); 
    	//表头：
    	this.eDelegator.add('click',this.headerCheckboxClickDele.bind(this),'input[eventDele=header_checkbox]'); //表头checkbox
    	//表头排序相关事件
        this.eDelegator.add('click',this.headerClickDele.bind(this),'div.sGrid_header_item_div'); //表头所有元素
        this.eDelegator.add('mouseenter',this.headerEnterDele.bind(this),'div.sGrid_header_item_div');//表头 hover
        this.eDelegator.add('mouseleave',this.headerLeaveDele.bind(this),'div.sGrid_header_item_div'); //表头 hover
        //表头拖拽列宽
        this.eDelegator.add('mousedown',this.headerDragWidthDele.bind(this),'div.sGrid_header_border_div'); //表头拖拽列宽
        
        //控制台:
        this.eDelegator.add('mouseenter',this.consoleEnterDele.bind(this),'input[eventDele=console]');//控制台 hover
        this.eDelegator.add('mouseleave',this.consoleLeaveDele.bind(this),'input[eventDele=console]'); //控制台 hover  
        this.eDelegator.add('click',this.consoleClickDele.bind(this),'input[eventDele=console]'); //控制台 click   
        
    	//表格内元素:
    	this.eDelegator.add('click',this.cellClickDele.bind(this),'div.sGrid_data_row_item_div'); //cell click,所有类型都会触发
    	this.eDelegator.add('click',this.actClickDele.bind(this),'div[eventDele=act]'); //cell act click 
    	
    	this.eDelegator.add('click',this.textClickDele.bind(this),'div[eventDele=text]'); //cell text click
    	this.eDelegator.add('click',this.dateClickDele.bind(this),'div[eventDele=date]'); //cell date click
    	this.eDelegator.add('click',this.selectClickDele.bind(this),'div[eventDele=select]'); //cell select click
    	this.eDelegator.add('click',this.pulltreeClickDele.bind(this),'div[eventDele=pulltree]'); //cell pulltree click
    	this.eDelegator.add('click',this.checkboxClickDele.bind(this),'input[eventDele=checkbox]'); //cell checkbox click
//    	if(this.options.type=='tree')
//    	this.eDelegator.add('click',this.gridtreeClickDele.bind(this),'div[eventDele=gridtree]'); //cell gridtree click
    	this.eDelegator.add('mouseenter',this.file2EnterDele.bind(this),'div[eventDele=file2]');//file2 cell enter
    	
    	
    	this.eDelegator.add('mouseenter',function(e,defEl){defEl.addClass('sGrid_data_row_div_hover')},'div.sGrid_data_row_div');//row hover
    	this.eDelegator.add('mouseleave',function(e,defEl){defEl.removeClass('sGrid_data_row_div_hover')},'div.sGrid_data_row_div'); //row hover
    	this.eDelegator.add('click',this.rowClickDele.bind(this),'div.sGrid_data_row_div'); //row click
    	this.eDelegator.add('dblclick',this.rowDblclickDele.bind(this),'div.sGrid_data_row_div'); //row dblclick
    	this.eDelegator.add('contextmenu',this.rowContextmenuDele.bind(this),'div.sGrid_data_row_div'); //row contextmenu
    	
    }

	,file2EnterDele:function(e,defEl){
		if(defEl.get('first'))return;
		defEl.set('first','true');
		
		var el=defEl, 
		type=defEl.get('type'), 
		elName=defEl.get('name'), 
		itemEl=this.getItemElByName(elName)[0],
		rowNum=this.getRowNum(defEl);
		
		var sGrid_data_row_div=this.getRow(el);
	    var dataObj=this.getOneRowData(sGrid_data_row_div);
	    var html = dataObj.tds[elName];
	    if(html)html = html['value'];	
	    
		el.getElement('div[name=tmp]').destroy();
		this.lazyInitFile2(itemEl,el,html,dataObj);
		
	}
	
	,collapseClickDele:function(e,defEl){
//		var el=defEl;
		this.toggle();					
	}


	,gridtreeClickDele:function(e,defEl){	
		var cell=defEl.getParent();
		this.treeClick(cell, e);
	    this.scrollHeader();
	}

	,checkboxClickDele:function(e,defEl){
		var el=defEl, 
		elName=defEl.get('name'), 
		itemEl=this.getItemElByName(elName)[0];						
	}
	
	
	
	
	,pulltreeClickDele:function(e,defEl){
		var el=defEl, 
		type=defEl.get('type'), 
		elName=defEl.get('name'), 
		itemEl=this.getItemElByName(elName)[0],
		rowNum=this.getRowNum(defEl);
		
		var treename = itemEl.get('treename');
	    var treeObj = $w(treename);
	    
	    var sGrid_data_row_div=this.getRow(el);
	    var dataObj=this.getOneRowData(sGrid_data_row_div);
	   
	    
	    if(treeObj.gridAddEvent != true) { //注册事件
	        var eventTarget = treeObj.select ? treeObj.select : treeObj;
	        
	        eventTarget.addEvent('onSelectHide', function(input) {
	            var cell = input.getParent('.sGrid_data_row_item_pulltree');
	            treeObj.select.selBox.store('lastCell', cell);
	            treeObj.options.pNode.inject(document.body);
	            treeObj.options.pNode.setStyle('display', 'none');
	            if(!cell)return;
	            cell.set('html', '');
	            var realvalue = input.get('realvalue');
	            var caption = input.get('value');
	            if(!$chk(realvalue))caption="";
	            cell.set('realvalue', realvalue);
	
	            this.updateCell(cell, realvalue, caption, true);
	
	            input.set('value', '');
	            input.set('realvalue', '');
	
	            if(cell.get('rule')) {//执行校验
	                if(!this.vObj.doValidate(cell).state) {//校验没有通过
	                    this.addError(this.getRow(cell).get('rowNum'), cell.get('name'));
	                } else {
	                    this.removeError(this.getRow(cell).get('rowNum'), cell.get('name'));
	                }
	            }
	
	        }.bind(this));
	
	        treeObj.gridAddEvent = true;
	    }
	    
	
	           
	    if(el.get('disable') == 'true')return;
	    treeObj.select.hide(); 
	    el.set('html', '');
	    var input = treeObj.options.pNode.getElement('input');
	    treeObj.options.pNode.inject(el);
	    treeObj.options.pNode.setStyle('display', '');
	    input.set('value', el.get('title'));
	    input.set('realvalue', el.get('realvalue'));
	    treeObj.select.showByJs = true;
	
	    this.addNextFocusEvent(treeObj.select.selBox);
	    //在此触发下拉树的onClickBefore事件
	    if(treeObj.options.onClickBefore)this.getFunc(treeObj.options.onClickBefore)[0](dataObj, el);
	    treeObj.select.selBox.focus();
	}


	,selectClickDele:function(e,defEl){
		var el=defEl, 
		type=defEl.get('type'), 
		rd = defEl.get('readonly')||defEl.getAttribute("readonly"),
		
		
		elName=defEl.get('name'), 
		itemEl=this.getItemElByName(elName)[0],
		rowNum=this.getRowNum(defEl);
		
	    if(el.get('disable') == 'true')return;
	    
	    if(!el.retrieve('space')){
	    	el.store("space", el.getParent('.sGrid_data_row_div'));
	    }
	    if(el.get('allDb')){
	    	el.store("allDb",JSON.decode(el.get('allDb')));
	    	el.erase('allDb');
	    }
	
	    if(itemEl.get('onBeforeClick'))this.getFunc(itemEl.get('onBeforeClick'))[0](this.getOneRowData(el), this.getRow(el), itemEl);
	
	    var text = el.get('text').trim();
	
	    if(el.get('createSelect') == 'true') {
	        return;
	    }
	    itemEl.pNode = el;  //el 正确的  itemEL是错误的
	
	    el.set('text', '');  //清除原来的html值
	
	    var sel = pc.getSelect4grid();
	    sel.gridMulti=this._isMulti(itemEl);
	    sel.gridSpace=this.getRow(el);
	
	    if(sel.box && sel.box.getParent('.sGrid_data_row_item_div')) {//上一次是在表格中被展现出来的
	        var oldEl = sel.box.getParent('.sGrid_data_row_item_div');
	        if(!sel.box.get('code')) {//没有值被选中，更新状态
	            oldEl.set('caption', '');
	            oldEl.set('code', '');
	            oldEl.set('realvalue', '');
	        }
	
	
	        var value = oldEl.get('text');
	        var realValue = oldEl.get('realvalue') || '';
	        var code = oldEl.get('code');
	
	        oldEl.set('code', code);       //为cell赋code值,用来标示唯一性
	        oldEl.set('realvalue', realValue);
	        //update更新数据，数据源更新成要提交的值
	        $w(oldEl.getParent('div[sword=SwordGrid]').get('name')).updateCell(oldEl, realValue, oldEl.get('caption') || '', true);
	        oldEl.set('createSelect', 'false');
	
	    }
	    sel.setValidate(this.vObj);
	    var dd = itemEl.get('disable');
	    itemEl.set('disable', '');
	    sel.initParam(itemEl, this);
	    itemEl.set('disable', dd);
	
	    sel.grid_onFinished = function(selectValue, code, realValue, allDb) {
	        el.set('caption', selectValue);
	        el.set('code', code);
	        el.set('realvalue', realValue);
	        el.store('allDb', allDb);
	        el.set('createSelect', 'false');
	
	        //                            el.set('text', selectValue);
	        this.updateCell(el, realValue, el.get('caption') || '', true);
	
	        if(el.get('rule')) {//执行校验
	            if(!this.vObj.doValidate(el).state) {//校验没有通过
	                this.addError(this.getRow(el).get('rowNum'), el.get('name'));
	            } else {
	                this.removeError(rowNum, elName);
	            }
	        }
	
	    }.bind(this);
	
	    sel.box.set('value', text);
	    sel.box.set('code', el.get('code'));   //在box上赋值，好让onfinish能取到
	    sel.box.set('realvalue', el.get('realvalue'));
	    if(rd=="true"){
	    	sel.box.set("readonly",true);
		    }
	    sel.show.delay(1, sel); //延迟执行是为了。。略过全局的click事件,不被hide掉
	
	    el.set('createSelect', 'true');
	   
	    //添加焦点转移事件
	//                this.addNextFocusEvent(sel.box);
	
	    sel.box.focus();
	    sel.box.focus(); //todo 为什么要2次才能获得焦点？？？
	}

	,dateClickDele:function(e,defEl){
		var el=defEl, 
		type=defEl.get('type'), 
		elName=defEl.get('name'), 
		rd = defEl.get('readonly')||defEl.getAttribute("readonly"),
		itemEl=this.getItemElByName(elName)[0],
		rowNum=this.getRowNum(defEl);
		
		if(el.get('disable') == 'true')return;
	    if(itemEl.get('onBeforeClick'))this.getFunc(itemEl.get('onBeforeClick'))[0](this.getOneRowData(el), this.getRow(el), itemEl);
	    var text = el.get('text');
	
	    if(el.get('createCalendar') == 'true') {
	        return;
	    }
	    itemEl.pNode = el;  //el 正确的  itemEL是错误的
	    el.set('html', '');  //清除原来的html值

	    var cal = pc.getCalendar4grid();

		
	    if(cal.dateInput && cal.dateInput.getParent('.sGrid_data_row_item_div')) {
	        var date = cal.dateInput.get('value');
	        var realvalue = this.getCalendar().getRealValue(this.getItemElByName(cal.dateInput.getParent('.sGrid_data_row_item_div').get('name')), date);
	
	        cal.dateInput.getParent('.sGrid_data_row_item_div').set('showvalue', date);
	        cal.dateInput.getParent('.sGrid_data_row_item_div').set('createCalendar', 'false');
	        //todo 以下代码可能会出问题，需要精确取到当前对象上下文
	        this.updateCell(cal.dateInput.getParent('.sGrid_data_row_item_div'), realvalue, date);//update更新数据
	        cal.clear();
	
	        cal.jsShow = false;
	
	    }
	
	    cal.setValidate(this.vObj);
	    cal.initParam(itemEl);
	    cal.dateInput.set('onHide', itemEl.get('onHide'));
	    cal.dateInput.set('onChange', itemEl.get('onChange'));
	    cal.dateInput.set('value', el.get('showvalue'));
	    cal.dateInput.set('oValue', el.get('realvalue'));
	    cal.grid_onFinished = function(date) {
	        var realvalue = this.getCalendar().getRealValue(itemEl, date);
	        //                         el.set('text', date);
	        this.removeError(rowNum, elName); //如果是通过日期控件输入日期的话，一定没有错误。
	        el.set('showvalue', date);
	        el.set('realvalue', realvalue);
	        this.updateCell(el, realvalue, date);//update更新数据，传入真实值
	        //                         cal.clear();
	        el.set('createCalendar', 'false');
	
	        cal.jsShow = false;
	        cal.onFinished = null;
	        //alert('finish off ');
	    }.bind(this);
	
	    cal.jsShow = true;
	    //                    cal.show(cal.dateInput);
	    cal.show.delay(1, cal, cal.dateInput);
	
	    el.set('createCalendar', 'true');
	    if(rd=="true"){
   		 cal.dateInput.set("readonly",true);
	    }
	    //添加焦点转移事件
	    this.addNextFocusEvent(cal.dateInput, cal);
	
	    cal.dateInput.focus();
	    cal.dateInput.focus();//todo 为什么要2次才能获得焦点？？？
		
	}

	,textClickDele:function(e,defEl){
		var el=defEl, 
		type=defEl.get('type'), 
		elName=defEl.get('name'), 
		itemEl=this.getItemElByName(elName)[0],
		rowNum=this.getRowNum(defEl);
		this.textClick(el, itemEl, type, elName, rowNum);
	}

	,consoleClickDele:function(e,defEl){
		var el=defEl;
		var name=el.get('name');
		var item=this.getConsoleItemByName(name);
		
		var consoleType = item.get('console');
        var tid = item.get('tid');
        var ctrl = item.get('ctrl');
        var check = item.get('check');
        var name = item.get('name');
		
        if(consoleType == 'delete') {

        	this.deleteRows({
                'tid':tid
                ,'ctrl':ctrl
                ,'check':check
                , 'onSuccess':this.getFunc(item.get('onSuccess'))[0]
                , 'onError':this.getFunc(item.get('onError'))[0]
                ,'postType':item.get('postType')
                ,'popMes':item.get('popMes')
                ,'delConfirm':item.get('delConfirm')
            });

        } else if(consoleType == 'deleting') {

	        	var els; //获得每行选中的checkbox
	            if(!$defined(check)) {    //没有传入参数，直接返回最后被单击行
	                els = this.dataDiv().getChildren('div.sGrid_data_row_click_div:not([status=delete]):not([cache=true])');
	            } else {
	                els = this.dataDiv().getElements('div:not([status=delete]) div input[name="' + check + '"][type="checkbox"][checked]');
	                if(els.length == 0) {
	                    els = this.dataDiv().getElements('div:not([status=delete]) div input[name="' + check + '"][type="radio"][checked]');
	                }
	            }
	            if(els.length == 0) {
	                pc.alert('请至少选择一行！');
	                return;
	            }
	
	            els.each(function(el) {
	                this.deleting(el);
	            }, this);

        } else if(consoleType == 'insert') {

            this.insertRow(this.getDataObjByInsertItem(item), this.combineItems(item), this.createNewRowNum(), null, item.get('where')); //合并后的增行配置项目，替换原有的类型和校验规则

        } else if(consoleType == 'treeInsertBrother') {

            this.treeInsertBrother(this.getDataObjByInsertItem(item), this.combineItems(item), this.createNewRowNum()); //合并后的增行配置项目，替换原有的类型和校验规则


        } else if(consoleType == 'treeInsertChild') {

        	var curLevel = 0;
            var checkedRow = this.getCheckedRow();
            if(checkedRow) {
                curLevel = checkedRow.getElement('div[treeLevel]').get('treeLevel') / 1;
            }

            var maxLevel = item.get('maxLevel') || -1;
            maxLevel = maxLevel / 1;
            if(maxLevel != -1 && curLevel + 1 > maxLevel) {
                var mes = item.get('maxMes') || '因为限制了增行的最大层数，所以不能在此处增行。';
                swordAlert(mes);
                return;
            }

            this.treeInsertChild(this.getDataObjByInsertItem(item), this.combineItems(item), this.createNewRowNum()); //合并后的增行配置项目，替换原有的类型和校验规则


        } else if(consoleType == 'save') {//保存更新和新增行操作

        	if(this.validate()) {

                //submit before
                if(item.get('onSubmitBefore')) {
                    var flag = this.getFunc(item.get('onSubmitBefore'))[0]();
                    if(flag == false)return;
                }

                var req = this.getReq({
                    'tid':tid
                    ,'ctrl':ctrl
                    ,'widgets':[this.getStatusGirdData()]
                });

                //----------------------------
                var popMes = item.get('popMes') != 'false';//是否自动弹出提示信息，默认为自动弹出
                pc.postReq({
                    'req':req
                    ,'postType':item.get('postType')
                    ,'onSuccess':function(res) {//onSuccess
                        if(popMes)this.alert('' + i18n.saveSuc);
                        this.commit();

                        if(item.get('onSuccess')) {
                            this.getFunc(item.get('onSuccess'))[0](req, res);
                        }
                    }.bind(this)
                    ,'onError':function (res) {//onError 出错的情况
                        if(popMes)this.alertError('' + i18n.saveFai);

                        if(item.get('onError')) {
                            this.getFunc(item.get('onError'))[0](req, res);
                        }
                    }.bind(this)
                });


            }

        } else if(consoleType == 'submitChecked') {

        	var item2 = this.getItemElByName(check);
            if(this.isCP() && item2.get('userClicked') == 'true') {
                if(this.allInCache() || item2.get('checkAllFlag') == 'false') {
                    if(this.getCheckedEls(check).length == 0) {
                        this.alertError("" + i18n.gridInsert);
                        return;
                    }
                }
            } else {
                if(this.getCheckedEls(check).length == 0) {
                    this.alertError("" + i18n.gridInsert);
                    return;
                }
            }

            var req = this.getReq({
                'tid':tid
                ,'ctrl':ctrl
                ,'widgets':[this.getCheckedData(check)]
            });

            pageContainer.postReq({
                'req':req
                ,'postType':item.get('postType')
                ,'onSuccess':function(res) {//onSuccess
                    if(item.get('onSuccess')) {
                        this.getFunc(item.get('onSuccess'))[0](req, res);
                    }
                }.bind(this)
                ,'onError':function (res) {//onError 出错的情况
                    if(item.get('onError')) {
                        this.getFunc(item.get('onError'))[0](req, res);
                    }
                }.bind(this)
            });

        } else if(consoleType == 'curPageData' || consoleType == 'allData' || consoleType == 'allNoDeleteData') {


        	var d;
            if(consoleType == 'curPageData') {
                d = this.getCurPageGirdData();
            } else if(consoleType == 'allData') {
                d = this.getAllGridData();
            } else if(consoleType == 'allNoDeleteData') {
                d = this.getAllNoDeleteGridData();
            }


            var req = this.getReq({
                'tid':tid
                ,'ctrl':ctrl
                ,'widgets':[d]
            });

            pageContainer.postReq({
                'req':req
                ,'postType':item.get('postType')
                ,'onSuccess':function(res) {//onSuccess
                    this.commit();
                    if(item.get('onSuccess')) {
                        this.getFunc(item.get('onSuccess'))[0](req, res);
                    }
                }.bind(this)
                ,'onError':function (res) {//onError 出错的情况
                    if(item.get('onError')) {
                        this.getFunc(item.get('onError'))[0](req, res);
                    }
                }.bind(this)
            });

        } else if(consoleType == 'button') {


        	if(item.get('onClick')) {
                this.getFunc(item.get('onClick'))[0]();
            }

        } else if(consoleType == 'excel') {
        	var d = this.getGridExcelInfo();
            var req = this.getReq({
                'tid':tid
                ,'ctrl':ctrl
                ,'widgets':d
            });
            pageContainer.postReq({
                'req':req
                ,'postType':item.get('postType')
                ,'onSuccess':function(res) {//onSuccess
                    this.commit();
                    if(item.get('onSuccess')) {
                        this.getFunc(item.get('onSuccess'))[0](req, res);
                    }
                }.bind(this)
                ,'onError':function (res) {//onError 出错的情况
                    if(item.get('onError')) {
                        this.getFunc(item.get('onError'))[0](req, res);
                    }
                }.bind(this)
            });
        } else {
            alert('gird[' + this.options.name + ']:SwordGrid无法处理控制台属性：' + consoleType);
        }
		
	}
	
	

	,consoleEnterDele:function(e,defEl){
		var el=defEl;
		el.addClass('sGrid_console_item_button_hover');
	}
	
	,consoleLeaveDele:function(e,defEl){
		var el=defEl;
		el.removeClass('sGrid_console_item_button_hover');
	}



    ,headerDragWidthDele:function(e,defEl){
    	
    	var sGrid_header_item_div=defEl.getParent();
    	
    	var height = this.scrollDiv.getHeight();
        var y = sGrid_header_item_div.getPosition().y;
        var x = sGrid_header_item_div._getPosition().x;
        var borderDiv = this.getBorderDiv();
        borderDiv.setStyles({
            'height':height + 'px'
            ,'left':e.page.x
            ,'top': y
            ,'display':''
        });
        borderDiv.headerItemDiv = sGrid_header_item_div;
        borderDiv.stManager = this;

        var maxX = this.getDragMaxX();//表格剩余空间
        var nextMaxX = this.getNextMaxX(sGrid_header_item_div);//下一个元素的空间

        borderDiv.maxX = maxX;

        borderDiv.drag.options.limit = {'x':[x + this.options.minItemX/1,e.page.x + maxX + nextMaxX],'y':[y,y]};
        borderDiv.drag.bound.start(e);
        e.stop();
    }

	,headerEnterDele:function(e,defEl){
		var el=defEl;
		var name=el.get('_for');
		var type=el.get('type');
		
		if (this.issort(el)) {//sort=false的时候，不执行排序，其他情况执行排序
            if (!['checkbox','button','rowNum','rowNumOnePage','radio'].contains(el.get('type'))) { //除了XX类型，其余类型注册排序功能
                if (!(el.get('tid') && el.get('type') != 'a')) {   // 有tid且不是a类型的 也不注册排序
                    el.addClass('sGrid_header_item_div_hover');
                }
            }
        }
	}
	
	,headerLeaveDele:function(e,defEl){
		var el=defEl;
		var name=el.get('_for');
		var type=el.get('type');
		
		if (this.issort(el)) {//sort=false的时候，不执行排序，其他情况执行排序
            if (!['checkbox','button','rowNum','rowNumOnePage','radio'].contains(el.get('type'))) { //除了XX类型，其余类型注册排序功能
                if (!(el.get('tid') && el.get('type') != 'a')) {   // 有tid且不是a类型的 也不注册排序
                    el.removeClass('sGrid_header_item_div_hover');
                }
            }
        }
	}


	,headerClickDele:function(e,defEl){
		var el=defEl;
		var name=el.get('_for');
		var type=el.get('type');
		
		if (this.issort(el)) {//sort=false的时候，不执行排序，其他情况执行排序
            if (!['checkbox','button','rowNum','rowNumOnePage','radio'].contains(el.get('type'))) { //除了XX类型，其余类型注册排序功能
                if (!(el.get('tid') && el.get('type') != 'a')) {   // 有tid且不是a类型的 也不注册排序
                        this.sortColumn(name);
                }
            }
        }
	}


	,headerCheckboxClickDele:function(e,defEl){

		 var el= defEl;
		 var name=el.get('_for');
		 
         if(el.get('checked')){
             this.dataDiv().getElements('div:not([cache=true]) div input[name="'+name+'"][type="checkbox"]:not(:disabled)').set('checked',true);
         }else{
             this.dataDiv().getElements('div:not([cache=true]) div input[name="'+name+'"][type="checkbox"]:not(:disabled)').set('checked',false);
         }

         this.fireEvent('onAllCheckClick',name);
		
	}

	,actClickDele:function(e,defEl){
		var el=defEl, 
		type=defEl.get('type'), 
		elName=defEl.get('name'), 
		itemEl=this.getItemElByName(elName)[0],
		rowNum=this.getRowNum(defEl);
		
		
		var act = itemEl.get('act');
		var tid = itemEl.get('tid');
		var ctrl=itemEl.get('ctrl');
		
 /*       var page=itemEl.get('page');
        var showRow=itemEl.get('showRow');*/
        
        var elName=itemEl.get('name');
        var msg = itemEl.get('msg');
        
		
		
		if(act=='delete'){//注册删除的单击事件
            //代码执行到这里el肯定不为null
            var popMes=itemEl.get('popMes')!='false';//是否自动弹出提示信息，默认为自动弹出
            var delConfirm=itemEl.get('delConfirm')||(''+i18n.gridDelConfirm);

                if(el.get('disable')=='true')return;
                if(popMes){
                     if (!confirm(delConfirm))return;
                }

                 var deletingRow=this.deleting(el);//标记删除
                 if(deletingRow==null)return; //是增行直接删除

                    //发送请求数据
                    var req = this.getReq({
                        'tid':tid
                        ,'ctrl':ctrl
                        ,'widgets':[this.getOneRowGirdData(deletingRow)]
                    });

                    pc.postReq({
                        'req':req
                        ,'postType':itemEl.get('postType')
                        ,'onSuccess':function(res) {
                            this.deleteRow(deletingRow);

                            if (itemEl.get('onSuccess')) {
                                this.getFunc(itemEl.get('onSuccess'))[0](req, res);
                            }
                        }.bind(this)
                        ,'onError':function (res) {
                            deletingRow.removeClass('sGrid_data_row_delete_div');

                            if (itemEl.get('onError')) {
                                this.getFunc(itemEl.get('onError'))[0](req, res);
                            }
                        }.bind(this)
                    })

                    //发送请求数据 end

        } else if (act=='deleting') {
           var deleteCaption=el.get('text');
           var cancel=itemEl.get('cancel')||''+i18n.cancel;

           

               if(el.get('disable')=='true')return;

               var row = this.getRow(el);

               //取消的操作
               if(row.get('status')=='delete'){
                   el.set('text',deleteCaption);
                   row.set('status','');
                   row.removeClass('sGrid_data_row_delete_div');
                   return;
               }

               //以下为标记删除操作-----
               if (row.get('status') != 'insert') {
                   el.set('text', cancel);
               }else {//是新增的行的时候直接执行删除操作
                   if (!confirm(''+i18n.gridInsertRowDel)) {
                      return;
                   }
               }
               this.deleting(el);

	
	    } else if (tid||ctrl) { //访问后台

             if(el.get('disable')=='true')return;

             var row=el.getParent('.sGrid_data_row_div');
            if (row.get('status') == 'insert') {//是新增的行的时候 不能执行此操作
                alert(''+i18n.gridSaveAlert);
                return;
            }

            var req = this.getReq({
                'tid':tid
                ,'ctrl':ctrl
                ,'widgets':[this.getOneRowGirdData(el)]
            });

            pc.postReq({
                'req':req
                ,'postType':itemEl.get('postType')
                ,'onSuccess':function(res) {
                    if (itemEl.get('onSuccess')) {
                        this.getFunc(itemEl.get('onSuccess'))[0](req, res);
                    }
                }.bind(this)
                ,'onError': function(res) {
                    if (itemEl.get('onError')) {
                        this.getFunc(itemEl.get('onError'))[0](req, res);
                    }
                }.bind(this)
            });		
	    }	
	}
	

	,cellClickDele : function(e, defEl) {
		var el = defEl, 
		elName = defEl.get('name'), 
		elType = defEl.get("type"),
		itemEl = this.getItemElByName(elName)[0];

		if (!(itemEl.get('_onClick')))
			return;
		if (el.get('disable') == 'true')
			return;
		var f=this.getFunc(itemEl.get('_onClick'))[0];
		var arg1=this.getOneRowData(el);
		var arg2=this.getRow(el);
		if(elType!="button"&&elType!="a"){
			f(arg1,arg2,el);
		}else{
			if(e.target.get("tag")=="span"){
				f(arg1,arg2,el);
			}
		}

	}

	,rowClickDele : function(e, defEl) {
		var obj = $(e.target);
		var type = obj.get('type');
		var tag = obj.get('tag');

		var sGrid_data_row_div = this.getRow(obj);
		var dataObj = this.getOneRowData(sGrid_data_row_div);
		
		
        if(this.options.checkMoudle=='true'){
            var obj=e.target;
            var type=obj.get('type');
            var tag=obj.get('tag');
            if(!(type=='checkbox'&&tag=='input')) {
                    this.dataDiv().getElements('input:not(:disabled)[type=checkbox][checked]').set('checked', false);
                    sGrid_data_row_div.getElements('input:not(:disabled)[type=checkbox]').set('checked', true);
            }
                sGrid_data_row_div.getElements('input:not(:disabled)[type=radio]').set('checked', true);

            var noneChecked = this.dataDiv().getElements('input[type=checkbox]:not([checked])').length;
            if (noneChecked == 0) {
                    this.getHeaderCheckboxs_noneChecked().set('checked', true);
                } else {
                    this.getHeaderCheckboxs_checked().set('checked', false);
                }
            } else {
                if(type == 'checkbox' && tag == 'input') {
                    var noneChecked = this.dataDiv().getElements('input[type=checkbox][name=' + obj.get('name') + ']:not([checked])').length;
                    var headerCheckbox = this.getHeaderCheckboxByName(obj.get('name'));
                    if(headerCheckbox == null)return;
                    if(noneChecked == 0) {
                        headerCheckbox.set('checked', true);
                        if(this.isCP()) {
                            var itemEl = this.getItemElByName(obj.get('name'));//有这种需求。。。
                            itemEl.set('userClicked', 'true');//客户点击过
                            itemEl.set('checkAllFlag', 'true');//客户点击全选按钮的最后状态
                        }
                    } else {
                        headerCheckbox.set('checked', false);
                    }
            }


        }


            this.dataDiv().getChildren('.sGrid_data_row_click_div').each(function(el) {
            el.removeClass('sGrid_data_row_click_div');
        });
        sGrid_data_row_div.addClass('sGrid_data_row_click_div');

        this.fireEvent('onRowClick', [dataObj,sGrid_data_row_div,e]);
	}
	
	
	,rowDblclickDele:function(e,defEl){
    	var obj = $(e.target);
    	var sGrid_data_row_div=this.getRow(obj);
        var dataObj=this.getOneRowData(sGrid_data_row_div);
    	this.fireEvent('onRowDbClick', [dataObj,sGrid_data_row_div,e]);
    }
    
	,rowContextmenuDele:function(e,defEl){
		var obj = $(e.target);
		var sGrid_data_row_div=this.getRow(obj);
        var dataObj=this.getOneRowData(sGrid_data_row_div);
		this.fireEvent('onRowRightClick', [dataObj,sGrid_data_row_div,e]);	
	}

});
